package co2.bean;

import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import co2.engine.Co2Constants;
import co2.pojos.MstUser;


@ManagedBean
@ViewScoped
public class EmbedFlashBean {

	private String path;
	
	@PostConstruct
	public void postCon(){
		try{
			Map map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
			String flashNm = map.get("flashNm").toString();
			StringBuffer sb = new StringBuffer();
			
			sb.append(Co2Constants.FLASH_PATH).append(flashNm).append(".swf");
			path = sb.toString();
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	public void back(){
		try{
			String requestPath = FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() ;
			Map map = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
			if(map.get("theUser123")!=null){
				MstUser mu = (MstUser) map.get("theUser123");
				if(mu.getRole()!=null && mu.getRole().equals("ADMIN")){
					FacesContext.getCurrentInstance().getExternalContext().redirect(requestPath+"/jsf/target/list_contents.jsf");
				}else{
					FacesContext.getCurrentInstance().getExternalContext().redirect(requestPath+"/jsf/target/detail_front.jsf");
				}
			}else{
				FacesContext.getCurrentInstance().getExternalContext().redirect(requestPath+"/jsf/target/detail_front.jsf");
			}
			
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	
	
	
	
	
	//getter and setter
	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	
}
